package com.yxx.mapper;

import com.github.pagehelper.Page;
import com.yxx.annotation.AutoFill;
import com.yxx.medicinecommon.enumeration.OperationType;
import com.yxx.medicinepojo.dto.ChineseWesternMedicineDTO;
import com.yxx.medicinepojo.dto.ChineseWesternMedicinePageQueryDTO;
import com.yxx.medicinepojo.entity.ChineseWesternMedicine;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineDetailListVO;
import com.yxx.medicinepojo.vo.ChineseWesternMedicineVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author yuxiangxun
 * @date 2024/9/7
 * @apiNote
 */
@Mapper
public interface ChineseWesternMedicineMapper {

    /**
     * 根据分类id查询中/西药的数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from chinese_western_medicine where category_id = #{categoryId}")
    Integer countByMedicineCategory_id(Long categoryId);

    /**
     * 药品分页查询
     * @param chineseWesternMedicinePageQueryDTO
     * @return
     */
    Page<ChineseWesternMedicineVO> pageQueryChineseWesternMedicine(ChineseWesternMedicinePageQueryDTO chineseWesternMedicinePageQueryDTO);

    /**
     * 根据分类id查询药品
     * @param chineseWesternMedicineVO
     * @return
     */
    List<ChineseWesternMedicineVO> list(ChineseWesternMedicineVO chineseWesternMedicineVO);

    /**
     * 新增药品
     * @param chineseWesternMedicine
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(ChineseWesternMedicine chineseWesternMedicine);

    /**
     * 修改药品
     * @param chineseWesternMedicine
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(ChineseWesternMedicine chineseWesternMedicine);

    /**
     * 回显数据，根据id查询药品信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id}")
    ChineseWesternMedicine ChineseWesternMedicineSelectUpdateById(Long id);

    /**
     * 根据药品id查询药品信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id}")
    ChineseWesternMedicine ChineseWesternMedicineById(Long id);

    /**
     * 根据药品ids集合删除药品信息
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据药品姓名查询药品id
     * @param name
     * @return
     */
    @Select("select id from chinese_western_medicine where name = #{name}")
    Long getIdByChineseWesternMedicineName(String name);

    /**
     * 组合药药品表+中西药表联立，根据组合药id获取中西药信息（集合）
     * @param id
     * @return
     */
    @Select("select cwm.* from chinese_western_medicine cwm left join setmedicine_medicine sm on cwm.id = sm.medicine_id where sm.setmedicine_id = #{id}")
    List<ChineseWesternMedicine> getChineseWesternMedicineStatusList(Long id);

    /**
     * 总中西药总览数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 根据组合药id查询中西药列表信息
     * @param id
     * @return
     */
    List<ChineseWesternMedicineDetailListVO> chineseWesternMedicineDetailListById(Long id);
}
